# Maintainer: Andrzej Giniewicz <gginiu@gmail.com>
# Maintainer: Bruno Pagani <archange@archlinux.org>

pkgname=python-blosc
pkgver=1.11.1
pkgrel=2
pkgdesc='Python wrapper for the extremely fast Blosc compression library'
arch=('loong64' 'x86_64')
url='http://python-blosc.blosc.org/'
license=('BSD')
depends=('python' 'blosc')
makedepends=('python-scikit-build' 'ninja')
checkdepends=('python-numpy' 'python-psutil')
optdepends=('python-numpy: for tests and benchmarks')
source=("https://github.com/Blosc/python-blosc/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz")
sha512sums=('21f8a697a3a902860a6ed72233984cf00c464ec0ddde9842a0c24b1e8e5ec4dd57b872096445a873d162d7529cba5c3666ba2a3ee3f9b1b18107d9636011281c')
b2sums=('cb348253a24258d2649ebc0604acbf936b8ccc2b28c42c69da2fee72ddf87eb17a24657bc5d3c0530193a60f482555ce4cc5d168a18d9c2d79a13410d40670bc')

build() {
  cd "${pkgname}-${pkgver}"

  export INCLUDE_SNAPPY=1 # Disabled by default for compatibility with non-C++ systems
  python setup.py build \
    --build-type none \
    -DUSE_SYSTEM_BLOSC=ON \
    -DCMAKE_C_FLAGS_INIT=-DNDEBUG
}

check() {
  local python_version=$(python -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
  local python_version_truncated=$(python -c 'import sys; print("".join(map(str, sys.version_info[:2])))')

  cd "${pkgname}-${pkgver}/_skbuild/linux-${CARCH}-${python_version}/setuptools/lib.linux-${CARCH}-cpython-${python_version_truncated}"

  PYTHONPATH="${PWD}:$PYTHONPATH" python -m blosc.test
}

package() {
  cd "${pkgname}-${pkgver}"

  python setup.py --skip-cmake install --skip-build --root="${pkgdir}" --optimize=1

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE.txt
}
